const mysql = require("mysql");

const pool = mysql.createPool({
    host:"127.0.0.1",
    user:'root',
    password:'root',
    database:'hty',
    port:3306
})

const exec = (sql,params) => {
    return new Promise(function(resolve,reject){
        pool.getConnection(function(err,conn){
            if (err) {
                console.log("连接数据库失败!" + err);
                reject(err)
            }
            conn.query(sql,params,function(err,result){
                if (err) {
                    console.log('执行sql语句失败!' + err);
                    reject(err)
                }
                resolve(result);
                conn.release();//释放连接
            })
        })
    })
}
module.exports = { exec }
 